#coding=utf-8

import math
import wx
import wx.html
from product import *
from ConfTool27 import conf

class MyPrinter():   
    @classmethod
    def getHtmlPrinter(cls, parent):    
        htmlP = wx.html.HtmlEasyPrinting(u"销售单预览", parent)
       
        setupData = htmlP.GetPageSetupData()
        #print setupData.GetEnableMargins()
        #print setupData.GetMarginTopLeft()
        #print setupData.GetMarginBottomRight()
        
        setupData.SetMarginTopLeft((18,1))
        setupData.SetMarginBottomRight((1,1))
        #print setupData.GetMarginTopLeft()
        #print setupData.GetMarginBottomRight()
        
        #print setupData.GetPaperSize()
        setupData.SetPaperSize((216, 140))
        #print setupData.GetPaperSize()
        
        return htmlP
        
    def preview():
        htmlP.PreviewText(self.htmlText)
##        self.printData = wx.PrintData() 
##        self.printData.SetPaperId(wx.PAPER_LETTER) 
##        self.printData.SetPrintMode(wx.PRINT_MODE_PRINTER) 
##        data = wx.PrintDialogData(self.printData) 
##        printout = wx.html.HtmlPrintout('printout') 
##        printout2 = wx.html.HtmlPrintout('printout for printing')
##        printout.SetHtmlText(self.htmlText)
##        printout2.SetHtmlText(self.htmlText)
##        self.preview = wx.PrintPreview(printout, printout2, data)#第一步创建预览设备 
##        if not self.preview.Ok(): 
##            wx.MessageBox("error") 
##            return
##        self.preview.SetZoom(100) 
##        pfrm = wx.PreviewFrame(self.preview, parentWindow.GetParent(), "This is a print preview")#第二步创建框架 
##        pfrm.Initialize()#第三步初始化框架
##        pfrm.SetPosition(parentWindow.GetPosition())#设置默认的位置 
##        pfrm.SetSize(parentWindow.GetSize())#设置打印预览框的大小 
##        pfrm.Show(True) 
        
    @classmethod
    def printSaleOrder(cls, parent, saleId, printDebt=True, printFund=False):
        #if saleId == '':
        #    return
            
        #soObj = CDataSaleOrder.getInstance({'id':saleId})
        soObj = CDataSaleOrder.findObj(saleId)
        if (soObj is None):
            print '[Error %s]' %saleId
            return
        
        if not soObj.isPrinted():
            soObj.setPrinted()
        
        #购货单位
        custId = soObj.getFieldVal('peerId')
        #custObj = CDataCustomer.getInstance({'id':custId})
        custObj = CDataCustomer.findObj(custId)
        #kh = custObj.getFieldVal('name')\
        #    + ' ' + custObj.getFieldVal('linkman')\
        #    + ' ' + custObj.getFieldVal('lm_phone') 
        #kh = custObj.getFieldVal('name')
        kh = custObj.getValue(custObj.COL_PRINTNAME)
        if (kh == ''):
            kh = custObj.getValue(custObj.COL_NAME)
    
        phone = ''
        if (CDataTableSale.includePhone()):
            phone = custObj.getValue(custObj.COL_LMPHONE)
        
        buyer = soObj.getValue(soObj.COL_BUYER)
        if (buyer != '' and buyer is not None and CDataTableSale.includeBuyer()):
                kh += ' (' + buyer + ')'
                
        #配送地址
        #dlvyId = soObj.getFieldVal('dlvyId')
        #if (dlvyId is None):
        #    dlvy = ''
        #else:
        #    dlvy = CDataDelivery.getFirstFieldVal({'id':dlvyId},'name')
        #dlvy = soObj.getFieldVal('dlvyAddr')
        dlvy = soObj.getDlvyAddr()
        
        #订单日期
        #billDate = datetime.date.today() #soObj.getFieldVal('billDate')
        billDate = soObj.getFieldVal('billDate')
        
        #产品列表
        filter = "billId='%s'" %saleId
        proObjList = CDataSaleDetail.fetch(filter)
        proDetails = []
        cnt = 0
        amount = 0
        for i in range(len(proObjList)):
            proObj = CDataProduct.getInstance({'id':proObjList[i].getFieldVal('proId')})
            row = []
            row.append(proObjList[i].getFieldVal('proName'))
            row.append(proObjList[i].getFieldVal('unit'))
            row.append(proObjList[i].getFieldVal('num'))
            row.append(proObjList[i].getFieldVal('price'))
            row.append(proObjList[i].getFieldVal('total'))
            row.append(proObjList[i].getFieldVal('memo'))
            # 240731 还是用缓存id，以免调整仓位后打印订单的仓位不更新
            row.append(proObj.getValue(proObj.COL_POSITION) 
               if proObj.getValue(proObj.COL_POSITION) != "" 
                  or proObj.getValue(proObj.COL_NOTCOUNTABLE) == 1 
                  or proObj.getValue(proObj.COL_CATEGORYID) == 33
               else "Y100")
            #pos = proObjList[i].getFieldVal('from_position')#.strip()#None会出bug
            # row.append(pos 
            #         if pos != "" 
            #             or proObj.getValue(proObj.COL_NOTCOUNTABLE) == 1 
            #             or proObj.getValue(proObj.COL_CATEGORYID) == 33
            #         else "Y100")

            if (proObj.getFieldVal('notcountable') == 0):
                cnt += row[2]
            amount += row[4]
            proDetails.append(row)
            
            # 以下代码书写方式不正确
            # proDetails.append[proObjList[i].getFieldVal('proName'), 
                                # proObjList[i].getFieldVal('unit'),
                                # proObjList[i].getFieldVal('num'),
                                # proObjList[i].getFieldVal('price'), 
                                # proObjList[i].getFieldVal('total')]
        
        if isinstance(billDate, unicode):
            date = billDate
        else:
            date = u'%d年%d月%d日' %(billDate.year, billDate.month, billDate.day)
        
        debt = None
        if (printDebt and CDataTableSale.includeDebt() and custObj.getValue(custObj.COL_TYPE) != 14):
            debt = custObj.getDebt()
            print (debt, amount)
            if abs(debt) < 0.01 or abs(debt-amount) < 0.01:
                debt = None
##            if (debt > 0.0):
##                date_debt = u'应付账款：' + str(debt) + u' 元'
            
        
        memo = soObj.getValue(soObj.COL_MEMO)
        if printFund:
            # 添加该客户未付订单信息
            fundStr = u''
            dataList = CDataSaleOrder.getBillAmount(custObj.getKeyVal())
            for id,total,paid,discount,unpaid in dataList:
                if unpaid > 0.0:
                    fundStr += u'%s-%s %g元, ' %(id[7:9], id[9:11], unpaid)
            if fundStr:
                memo = u'%s 【%s】' %(memo, fundStr[:-2])
                    
        #打印设置
        htmlP = cls.getHtmlPrinter(parent)
        htmlText = cls.makeSaleOrderHtml(saleId, kh, dlvy, date, debt, proDetails, cnt, amount, memo, phone)
        htmlP.SetHeader(u"<div align='right'><tr>第@PAGENUM@/@PAGESCNT@页</tr></div>")
        # footer = u'地址：南宁市五一路南四里8号(五一车管所对面)\n' 
        # footer += u'电话：0771-2412420   18978819291\n'
        # footer += u'本公司专业经营各类渔牧养殖、工业、农业、建筑、家居用筛网，铁钉铁线，聚乙烯醇，保温钉胶水等'
        # htmlP.SetFooter(footer)
        htmlP.PreviewText(htmlText)
    
    @classmethod    
    def makeSaleOrderHtml(cls, saleId, kh, dlvy, date, debt, proDetails, cnt, amount, memo='', phone=''):
        maxProLines = 12
        if (len(proDetails) > maxProLines):
            htmlText2 = cls.makeSaleOrderHtml(saleId, kh, dlvy, date, debt, proDetails[maxProLines:], cnt, amount)
            bLastPage = False
            curLines = maxProLines
        else:
            htmlText2 = ''
            bLastPage = True
            curLines = len(proDetails)
        
        tblSale = CDataTableSale.getTableSale()
        header = tblSale.getValue(CDataTableSale.iTitle).replace(' ', '&nbsp;')
        footer = tblSale.getValue(CDataTableSale.iFooter).replace(' ', '&nbsp;')
        footer = footer.split('\n')
        
        phoneStr = ''
        if (phone != ''):
            if len(phone) >= 11:
                phoneStr = u'电话：%s&nbsp;%s&nbsp;%s' %(phone[:3],phone[3:7],phone[7:])
            else:
                phoneStr = u'电话：%s' %phone
           
        debtStr = ''
        if debt is not None:
            debtStr = u'应付：%g元' %debt
        
        htmlText = u'''<h3 align='center'>%s</h3>
                    <table align='center' width='99%%'>
                    <tr>
                    <td align='left'>单位：%s</td>
                    <td align='left'>%s</td>
                    <td align='right'>单号：%s</td>
                    </tr>
                    <tr>
                    <td align='left'>配送：%s</td>
                    <td align='left'><b>%s</b></td>
                    <td align='right'>日期：%s</td>
                    </tr>
                    </table>''' %(header, kh, phoneStr, saleId, dlvy, debtStr, date)
        
        htmlText += u'''<table bgcolor='white' border='1px dashed' cellpadding='0' cellspacing='1' align='center' width='99%%'>
                    <tr>
                    <th width='5%'>序号</th>                    
                    <th width='32%'>品名</th>
                    <th width='8%'>单位</th>
                    <th width='10%'>数量</th>
                    <th width='10%'>单价</th>
                    <th width='10%'>小计</th>
                    <th width='17%'>备注</th>
                    <th width='8%'>仓位</th>
                    </tr>
                '''
                
        bgColor = ['White', 'White', 'Silver'] 
        for i in range(curLines):
            price = '---' if proDetails[i][3]==0.0 else '%g' %proDetails[i][3]
            total = '---' if proDetails[i][4]==0.0 else '%g' %proDetails[i][4]
            htmlText += u'''<tr bgcolor='%s'>
                <td>%d</td>                
                <td align='left'>&nbsp;&nbsp; %s</td>
                <td>%s</td>
                <td align='right'>%g &nbsp;&nbsp;</td>
                <td align='right'>%s &nbsp;&nbsp;</td>
                <td align='right'>%s &nbsp;&nbsp;</td>
                <td align='left'>&nbsp;%s</td>
                <td>%s</td>
                </tr>
                ''' %(bgColor[i%3], i+1, proDetails[i][0], 
                    proDetails[i][1],
                    proDetails[i][2],
                    price, total, proDetails[i][5], proDetails[i][6])
        if (bLastPage):
            sCnt = '%g' %cnt
            sAmount = '%g' %amount
        else:
            sCnt = '---'
            sAmount = '---'
        
        htmlText += u'''<tr>
                    <td colspan='3'><b>合计</b></td>
                    <td align='right'>%s  &nbsp;&nbsp;</td>
                    <td align='right'>---  &nbsp;&nbsp;</td>
                    <td align='right'><b>%s</b>  &nbsp;&nbsp;</td>
                    <td align='right'></td>
                    <td></td>
                    </tr>
                    </table>
                ''' %(sCnt, sAmount)
                # 仓库都不看备注，所以去掉
                #     <tr>
                #     <td>备注</td>
                #     <td colspan='7' align='left'>&nbsp;&nbsp;<b>%s</b></td>
                #     </tr>

                #     </table>
                # ''' %(sCnt, sAmount, memo)
                        
##        htmlText += u'''<table  align='center' width='80%%'>
##                <tr><td align='left'>地址：南宁市五一路南四里8号(五一车管所对面) &nbsp;&nbsp;&nbsp;&nbsp; 电话：0771-2412420 &nbsp;&nbsp; 18978819291</td></tr>
##                <tr><td align='left'>账号：邮政6210956110000142984 &nbsp;&nbsp; 农行6228450830043215314 &nbsp;&nbsp; 户名：吕文光</td></tr>                
##                <tr><td align='left'>本公司专业经营各类渔牧养殖、工业、农业、建筑筛网，铁钉铁线，聚乙烯醇，保温钉胶水等</td></tr> 
##                </table>
##            '''
        htmlText += u'''<table  align='center' width='80%%'>'''
        for str in footer:
            htmlText += u'''<tr><td align='left'>%s</td></tr> '''   %(str)
        htmlText += u'''</table>'''
        return htmlText + htmlText2
        
        
class MyPrinterSO(MyPrinter):
        
    def __init__(self, saleId=''):
        MyPrinter.__init__(self)
        
        if saleId == '':
            return
        
        self.soObj = CDataSaleOrder.getInstance({'id':saleId})
        if (self.soObj is None):
            print '[Error %s]' %saleId
            return
            
        custId = self.soObj.getFieldVal('peerId')
        self.custObj = CDataCustomer.getInstance({'id':custId})
        
        #dlvyId = self.soObj.getFieldVal('dlvyId')
        #self.dlvyObj = CDataDelivery.getInstance({'id':dlvyId})
        #dlvy = self.dlvyObj.getFieldVal('name')
        
        kh = self.custObj.getFieldVal('name')\
            + self.custObj.getFieldVal('linkman')\
            + self.custObj.getFieldVal('lm_phone')        
        
        dlvy = self.soObj.getDlvyAddr()#CDataDelivery.getFirstFieldVal({'id':self.soObj.getFieldVal('dlvyId')}, 'name')

        billdate = self.soObj.getFieldVal('billDate')
        
        self.htmlText = u'''<h3 align='center'>龙光筛网销售单</h3>
                    <table align='center' width='99%%'>
                    <tr>
                    <td align='left'>购货单位：%s</td>
                    <td align='right'>单号：%s</td>
                    </tr>
                    <tr>
                    <td align='left'>配送方式：%s</td>
                    <td align='right'>开单日期：%s</td>
                    </tr>
                    </table>''' %(kh, saleId, dlvy, billdate)
        
##        self.proList = []
        filter = "billId='%s'" %saleId
        proObjList = CDataSaleDetail.fetch(filter)
       
##        for proStr in proListStr:
##            pro = CDataSaleDetail.convertToObj(proStr)
##            self.proList.append(pro)
            
        self.htmlText += u'''<table bgcolor='white' border='10px dashed' cellpadding='0' cellspacing='1' align='center' width='99%%'>
                    <tr>
                    <th width='5%'>序号</th>
                    <th width='35%'>品名</th>
                    <th width='10%'>单位</th>
                    <th width='15%'>数量</th>
                    <th width='15%'>单价</th>
                    <th width='15%'>小计</th>
                    </tr>
                '''
        totalNum = 0        
        for i in range(len(proObjList)):
            self.htmlText += u'''<tr>
                <td>%d</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                <td>%s</td>
                </tr>
                ''' %(i+1, proObjList[i].getFieldVal('proName'), 
                    proObjList[i].getFieldVal('unit'),
                    proObjList[i].getFieldVal('num'),
                    proObjList[i].getFieldVal('price'),
                    proObjList[i].getFieldVal('total'))
            totalNum += proObjList[i].getFieldVal('num')
            
        # fk = u'''已付￥%d 未付￥%d 优惠￥%d''' %(self.soObj.getFieldVal('paid'),
                        # self.soObj.getFieldVal('unpaid'),
                        # self.soObj.getFieldVal('discount'))        
        fk = u'付款情况'
        self.htmlText += u'''<tr>
                    <td colspan='3'><b>合计</b></td>
                    <td>%d</td>
                    <td></td>
                    <td>%s</td>
                    </tr>
                    <tr>
                    <td>付款情况：</td>
                    <td colspan='5'>%s</td>
                    </tr>

                    <tr>
                    <td>备注</td>
                    <td colspan='5'>%s</td>
                    </tr>

                    </table>
                ''' %(totalNum, self.soObj.getFieldVal('total'), fk,
                        self.soObj.getFieldVal('memo'))
                        
        self.htmlText += u'''<table  align='center' width='80%%'>
                <tr><td align='left'>地址：南宁市五一路南四里8号(五一车管所对面)</td></tr>
                <tr><td align='left'>电话：0771-2412420 &nbsp;&nbsp;&nbsp;&nbsp; 18978819291</td></tr>
                
                </table>
            '''
       #     <tr><td align='left'>本公司主要批发经营：</td></tr>
  # <tr><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;常用筛网：焊网，钢板网，防蚊纱窗，网片，圆孔网，土工布(无纺布)</td></tr>
   ##            <tr><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;养殖网：塑料平网，鸡网，猪床网，鸽笼</td></tr>
     #           <tr><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;工地网系列：安全网，聚乙烯醇（速溶胶丝），胶水，保温钉</td></tr>
      #          <tr><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;砂浆网，批灰网，网格布，收口网，钢筋网片</td></tr>


class TagPrintout(wx.Printout):
    ''' 标签打印类 '''

    def __init__(self, title, billid):

        wx.Printout.__init__(self, title)

        # 获取各页的数据内容
        self.m_billid = billid
        self.m_data = CDataSaleDetail.GetPrintTagData(self.m_billid)

        self.m_pages = []
        for cust_name, proName, num, unit, package in self.m_data:
            for i in range(int(math.ceil(num/(1 if package<1 else package)))):
                self.m_pages.append([cust_name, proName, num, unit, i+1, int(math.ceil(num/(1 if package<1 else package)))])
        print self.m_pages 
        self.numPages = len(self.m_pages)
        self.COL_CUSTNAME = 0
        self.COL_PRONAME = 1
        self.COL_NUM = 2
        self.COL_UNIT = 3
        self.COL_IDX = 4
        self.COL_PAGE = 5

    def HasData(self):
        return self.numPages>0

    def HasPage(self, page):
        return page <= self.numPages

    def GetPageInfo(self):
        return (1, self.numPages, 1, self.numPages)

    def CalculateScale(self, dc):
        # Scale the DC such that the printout is roughly the same as
        # the screen scaling.
        ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
        ppiScreenX, ppiScreenY = self.GetPPIScreen()
        logScale = float(ppiPrinterX)/float(ppiScreenX)

        # Now adjust if the real page size is reduced (such as when
        # drawing on a scaled wx.MemoryDC in the Print Preview.)  If
        # page width == DC width then nothing changes, otherwise we
        # scale down for the DC.
        pw, ph = self.GetPageSizePixels()
        dw, dh = dc.GetSize()
        scale = logScale * float(dw)/float(pw)

        # Set the DC's scale.
        dc.SetUserScale(scale, scale)

        # Find the logical units per millimeter (for calculating the
        # margins)
        self.logUnitsMM = float(ppiPrinterX)/(logScale*25.4)    

    def OnPreparePrinting(self):
        # calculate the number of pages
        self.numPages = len(self.m_pages)
        
    def OnPrintPage(self, pageNum):
        
        #print ("OnPrintPage", pageNum)
        paper_witdh_mm = 60
        paper_height_mm = 40

        dc = self.GetDC()
        self.CalculateScale(dc)
        font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u"微软雅黑")
        dc.SetFont(font)
        self.lineHeight = dc.GetCharHeight() 

        dc.DrawRectangle(0,0,paper_witdh_mm*self.logUnitsMM,paper_height_mm*self.logUnitsMM)

        x = 2*self.logUnitsMM
        y = self.lineHeight
        dc.DrawText(self.m_pages[pageNum-1][self.COL_CUSTNAME], x, y)
        y += self.lineHeight
        y += 5

        font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, False, u"楷体")
        dc.SetFont(font)
        y += self.draw_text_mul(u"%s x%g%s  第%g/%g件"%(self.m_pages[pageNum-1][self.COL_PRONAME]
                , self.m_pages[pageNum-1][self.COL_NUM]
                , self.m_pages[pageNum-1][self.COL_UNIT]
                , self.m_pages[pageNum-1][self.COL_IDX]
                , self.m_pages[pageNum-1][self.COL_PAGE])
            , dc, x, y, paper_witdh_mm*self.logUnitsMM-x)
        #y += self.lineHeight
        y += 5

        font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u"微软雅黑")
        dc.SetFont(font)

        dc.DrawText(u"共%d/%d页" %(pageNum, self.numPages)
            , x, y)
        y += self.lineHeight

        #dc.DrawText(u"龙光筛网", 0, 0)

        # x = 10 * self.logUnitsMM
        # y = self.lineHeight
        # y += self.draw_text_mul(self.m_pages[pageNum-1][self.COL_CUSTNAME]
        #         , dc, x, y
        #         , paper_witdh_mm * self.logUnitsMM - 20*self.logUnitsMM)

        # y += self.draw_text_mul(self.m_pages[pageNum-1][self.COL_PRONAME]
        #         , dc, x, y
        #         , paper_witdh_mm * self.logUnitsMM - 20*self.logUnitsMM)

        # y += self.draw_text_mul(str(self.m_pages[pageNum-1][self.COL_NUM])+" "+self.m_pages[pageNum-1][self.COL_UNIT]
        #         , dc, x, y
        #         , paper_witdh_mm * self.logUnitsMM - 20*self.logUnitsMM)

        # image = wx.Image('./qrcode.png', wx.BITMAP_TYPE_ANY)
        # dc.DrawBitmap(image.Scale(20*self.logUnitsMM,20*self.logUnitsMM).ConvertToBitmap()
        #     , (paper_witdh_mm - 20)*self.logUnitsMM
        #     , 0
        #     , True)

        # font = wx.Font(8, wx.TELETYPE, wx.NORMAL, wx.NORMAL)
        # dc.SetFont(font)
        # dc.DrawText(u"扫码加微信", paper_witdh_mm * self.logUnitsMM - 20*self.logUnitsMM, 20*self.logUnitsMM + 10)

        return True

    def draw_text_mul(self, text, dc, x, y, max_width):
        ''' 绘制换行文本 '''

        # 获取文本宽度和高度
        text_extent = dc.GetTextExtent(text)
        print text_extent
        
        # 拆分文本为多行
        lines = self.wrap_text(text, dc, max_width)
        
        height = 0
        # 逐行绘制文本
        for line in lines:
            dc.DrawText(line, x, y)
            y += text_extent[1]  # 增加行高
            height += text_extent[1]

        return height

    def wrap_text(self, text, dc, max_width):
        ''' 超长文本，自动按空格换行 '''
        words = text.split(' ')
        lines = []
        current_line = ''
        
        for word in words:
            test_line = current_line + word + ' '
            test_width, _ = dc.GetTextExtent(test_line)
            
            if test_width > max_width:
                lines.append(current_line.strip())
                current_line = word + ' '
            else:
                current_line = test_line
        
        if current_line.strip():
            lines.append(current_line.strip())
        
        return lines


class TagPrinter():

    @staticmethod
    def printTag(parent, billid):
        # 标签打印测试
        pdata = wx.PrintData()
        #pdata.SetPaperId(wx.PAPER_LETTER)
        #pdata.SetOrientation(wx.PORTRAIT)
        #margins = (wx.Point(10,10), wx.Point(10,10))

        tag_printer = conf.get_or_default('print', 'tag_printer', '')
        print tag_printer
        if (tag_printer):
            pdata.SetPrinterName(tag_printer)

        data = wx.PrintDialogData(pdata)

        title = CDataSaleOrder.getPeerNameByBill(billid)
 
        printout = TagPrintout(title, billid)
        printout2 = TagPrintout(title, billid) #管理预览与实际打印 printout 必须用2个实例

        if (not printout.HasData()):
            wx.MessageBox(u"无法打印，没有商品！", "Error")
            return

        preview = wx.PrintPreview(printout # 管理预览
                    , printout2 # 用于实际的打印，为None则 Print 按钮不显示 
                    , data) # 是一个 wx.PrintData 对象或一个 wx.PrintDialogData 对象，指定了的话，那么它被用于控制该打印预览
        preview.SetZoom(100)
        if not preview.Ok():
            wx.MessageBox(u"无法创建预览！", "Error")
        else:
            # create the preview frame such that it overlays the app frame
            frame = wx.PreviewFrame(preview, parent, title)
            frame.Initialize()
            frame.Show()

#if __name__ == "__main__":
#    TagPrinter.printTag("XS-20241120-00023")